FROM node:12.22.0 AS builder_web

WORKDIR /app

ADD ./package.json /app/package.json
ADD ./yarn.lock /app/yarn.lock

# 安装依赖
RUN yarn config set @yunke:registry https://registry-npm.myscrm.cn/repository/yunke/ && \
  npm config set registry https://registry.npm.taobao.org && \
  yarn --frozen-lockfile --check-files

# 将docker构建参数转换到环境变量
ARG IMAGE_TAG
ENV IMAGE_TAG=$IMAGE_TAG

ADD . /app
# 构建代码
RUN yarn build

FROM yunke-registry.cn-hangzhou.cr.aliyuncs.com/yued/nginx-base:1.21.0-alpine-1.0.6
# 同步cdn标识
LABEL sync-cdn="true" sync-cdn-pre-action="/docker-entrypoint.d/replace.sh" sync-cdn-by-deploy-env="1" sync-cdn-target="/app/dist" probe="none"

RUN mkdir -p /var/log/service/access && mkdir -p /var/log/service/err

# CDN同步脚本默认从/app/dist目录读文件
COPY --from=builder_web /app/dist /app/dist
COPY --from=builder_web /app/config/nginx.conf /etc/nginx/conf.d/default.conf
